#!/usr/bin/python
# coding=utf-8
from flask import json

import login
from public import verification, config
from public.http import POST

url = config.domain + '/user/summary'

authkey = login.authkey()


#  查询用户简单信息
def summary():
    values = {"name": "382662065", "oemid": "VSTC"}
    datajson = json.loads(POST(url, values))
    ret = datajson["ret"]
    return ret


#  查询不存在的用户
def summary_1():
    values = {"name": "382662065111111111", "oemid": "VSTC"}
    datajson = json.loads(POST(url, values))
    ret = datajson["ret"]
    return ret


#  参数不全
def summary_2():
    values = {"name": "382662065111111111"}
    datajson = json.loads(POST(url, values))
    ret = datajson["ret"]
    return ret


url_show = config.domain + '/user/show'


#  查询用户简单信息
def show():
    values = {"userid": "150650", "authkey": authkey}
    datajson = json.loads(POST(url_show, values))
    ret = datajson["ret"]
    return ret


#  参数不全
def show_1():
    values = {"authkey": authkey}
    datajson = json.loads(POST(url_show, values))
    ret = datajson["ret"]
    return ret


#  授权码失效
def show_2():
    values = {"userid": "150650", "authkey": "授权码失效"}
    datajson = json.loads(POST(url_show, values))
    ret = datajson["ret"]
    return ret


#  用户不存在
def show_3():
    values = {"userid": "1506501111111", "authkey": authkey}
    datajson = json.loads(POST(url_show, values))
    ret = datajson["ret"]
    return ret


url_updata_1 = config.domain + '/user/update/realname'


# 正常修改
def update():
    values = {"userid": "150650", "authkey": authkey, "value": "这是我的名字"}
    datajson = json.loads(POST(url_updata_1, values))
    ret = datajson["ret"]
    return ret


# 缺少参数
def update_1():
    values = {"authkey": authkey, "value": "这是我的名字"}
    datajson = json.loads(POST(url_updata_1, values))
    ret = datajson["ret"]
    return ret


# 授权码错误
def update_2():
    values = {"userid": "150650", "authkey": "授权码错误", "value": "这是我的名字"}
    datajson = json.loads(POST(url_updata_1, values))
    ret = datajson["ret"]
    return ret


# 用户不存在
def update_3():
    values = {"userid": "1506501111111", "authkey": authkey, "value": "这是我的名字"}
    datajson = json.loads(POST(url_updata_1, values))
    ret = datajson["ret"]
    return ret


url_updata_2 = config.domain + '/user/update/password'


# 正常修改
def update_password():
    values = {"userid": "150650",
              "authkey": authkey,
              "old": "e10adc3949ba59abbe56e057f20f883e",
              "pwd": "e10adc3949ba59abbe56e057f20f883e"}

    datajson = json.loads(POST(url_updata_2, values))
    ret = datajson["ret"]
    return ret


# 缺少参数
def update_password_1():
    values = {#"userid": "150650",
              "authkey": authkey,
              "old": "e10adc3949ba59abbe56e057f20f883e",
              "pwd": "e10adc3949ba59abbe56e057f20f883e"}
    datajson = json.loads(POST(url_updata_2, values))
    ret = datajson["ret"]
    return ret


# 授权码错误
def update_password_2():
    values = {"userid": "150650",
              "authkey": "授权码是错误的",
              "old": "e10adc3949ba59abbe56e057f20f883e",
              "pwd": "e10adc3949ba59abbe56e057f20f883e"}
    datajson = json.loads(POST(url_updata_2, values))
    ret = datajson["ret"]
    return ret


# 用户不存在
def update_password_3():
    values = {"userid": "150650111111111",
              "authkey": authkey,
              "old": "e10adc3949ba59abbe56e057f20f883e",
              "pwd": "e10adc3949ba59abbe56e057f20f883e"}
    datajson = json.loads(POST(url_updata_2, values))
    ret = datajson["ret"]
    return ret

# 用户不存在
def update_password_4():
    values = {"userid": "150650",
              "authkey": authkey,
              "old": "e10adc3949ba59abbe56e057f20f883e1",
              "pwd": "e10adc3949ba59abbe56e057f20f883e"}
    datajson = json.loads(POST(url_updata_2, values))
    ret = datajson["ret"]
    return ret

if __name__ == '__main__':
    verification(summary(), "查询用户简单信息", 200)
    verification(summary_1(), "查询不存在的用户", 404)
    verification(summary_2(), "参数不全", 400)

    verification(show(), "正常获取", 200)
    verification(show_1(), "参数不全", 400)
    verification(show_2(), "授权码失效", 401)
    verification(show_3(), "用户不存在", 404)

    verification(update(), "正常更新", 200)
    verification(update_1(), "缺少参数", 400)
    verification(update_2(), "授权码错误", 401)
    verification(update_3(), "用户不存在", 404)

    verification(update_password(), "正常更新", 200)
    verification(update_password_1(), "缺少参数", 400)
    verification(update_password_2(), "授权码错误", 401)
    verification(update_password_3(), "用户不存在", 404)
    verification(update_password_4(), "旧密码错误", 401)
